package com.lwlk.util.functional;

import java.util.Iterator;

public class IteratorOffer<T> implements Offer<Iterator<T>> {

    private final Offer<Boolean> hasNext;

    private final Offer<T> next;

    private IteratorOffer(Offer<Boolean> hasNext, Offer<T> next) {
        this.hasNext = hasNext;
        this.next = next;
    }

    @Override
    public Iterator<T> call() {
        return new Iterator<T>() {
            @Override public boolean hasNext() { return hasNext.call(); }
            @Override public T next() { return next.call(); }
        };
    }

    public static <T> IteratorOffer<T> make(Offer<Boolean> hasNext, Offer<T> next) {
        return new IteratorOffer<>(hasNext, next);
    }
}